package com.example.myapplication;

import android.content.Context;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

public class MainActivity extends AppCompatActivity {


    private AppCompatTextView contentTextView;
    private Context context = this;
    private AppCompatEditText serach_edit;
    private AppCompatTextView serach_cx;
    private AppCompatTextView contextTitle;
    private LinearLayoutCompat jc_info;
    private AppCompatTextView defaultTextView;
    private String city = "";


    private RecyclerView recyclerViews;




    @Override
    public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
        super.onCreate(savedInstanceState);
        //实例化控件
        contentTextView = findViewById(R.id.contentTextView);
        serach_edit = findViewById(R.id.serach_edit);
        serach_cx = findViewById(R.id.serach_cx);
        contextTitle = findViewById(R.id.contextTitle);
        jc_info = findViewById(R.id.jc_info);
        recyclerViews = findViewById(R.id.RecyclerViews);
        defaultTextView = findViewById(R.id.defaultTextView);
        //初始化数据
        OkGo.<String>get("https://tianqiapi.com/api?version=v6&appid=65716696&appsecret=pPQF7EgL").execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                WeatherBean weatherBean = new Gson().fromJson(response.body(), WeatherBean.class);
                defaultTextView.setText("城市：");
                defaultTextView.append(weatherBean.getCity() + "(" + weatherBean.getCityEn() + ")");
                defaultTextView.append("\n天气：");
                defaultTextView.append(weatherBean.getTem2() + "°C" + "~" + weatherBean.getTem1() + "°C，" + weatherBean.getWea());
                defaultTextView.append("\n风向：");
                defaultTextView.append(weatherBean.getWin() + " ， " + weatherBean.getWinSpeed() + " ，" + weatherBean.getWinMeter());
                defaultTextView.append("\n空气：");
                defaultTextView.append(weatherBean.getAirLevel() + " ， PM2.5的值为 " + weatherBean.getAirPm25());
                defaultTextView.append("\n提示：");
                defaultTextView.append(weatherBean.getAirTips() + "");
            }
        });

    }

}
